#!/bin/bash

PROJECT_ROOT=$(cd `dirname $0/`/..;pwd)

echo $PROJECT_ROOT
cd $PROJECT_ROOT
echo "=========== 1.0 before generate zip file ==============="
ls

if [[ ! -d "$PROJECT_ROOT/code" ]]; then
    echo "code file not exist..."
    exit 1
fi

if [[ ! -d "$PROJECT_ROOT/introduction" ]]; then
    echo "introduction file not exist..."
    exit 1
fi

if [[ ! -d "$PROJECT_ROOT/.codelabs" ]]; then
    echo "metadata file not exist..."
    exit 1
fi

echo "====== 2.0 generate tar.gz file ======"
cd $PROJECT_ROOT/code
mvn -e clean -U -Dmaven.test.skip package

cd $PROJECT_ROOT/
tar -czvf $PROJECT_ROOT/huaweicloud-css-createsnapshot-java-${CID_BUILD_TIME}.tar.gz *
echo "tar is done, ls you need:"
ls
echo "====== 3.0 after generate file ======"
ls -al $PROJECT_ROOT/code/target